﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DataAccess.OnlineDeposit;
using System.Data;
using System.Data.SqlClient;
using FOModels.OnlineDeposit;
using System.Net;
namespace Bussiness.OnlineDeposit
{
    public class OnlineDepositBLL
    {
        private OnlineDepositDAL dal;
        public OnlineDepositBLL()
        {
            dal = new OnlineDepositDAL();
        }
        public int UpdateStatus(OnlineDepositApplyModels card)
        {
            if (dal.UpdateStatus(card) > 0)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
        public int DeleteOnlineDepositApply(int SavingDepositApplyID)
        {
            if (dal.DeleteOnlineDepositApply(SavingDepositApplyID) > 0)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
        public int OnlineDepositApply(int DepositSavingID, OnlineDepositApplyModels card)
        {
            if (dal.OnlineDepositApply(DepositSavingID, card) > 0)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
        public OnlineDepositApplyModels getcontractbyid(int cardapplyid)
        {

            OnlineDepositApplyModels fur = new OnlineDepositApplyModels();
            DataTable tb = dal.getcontractbyid(cardapplyid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new OnlineDepositApplyModels();
                    fur.OnlineDepositApplyID = int.Parse(row[0].ToString());
                    fur.OnlineDepositID = int.Parse(row[1].ToString());
                    fur.CustomerName = row[2].ToString();
                    fur.CustomerEmail = row[3].ToString();
                    fur.CustomerPhone = row[4].ToString();
                    fur.CustomerIncome = row[5].ToString();
                    fur.CustomerDOB = row[6].ToString();
                    fur.StatusID = int.Parse(row[7].ToString());
                    fur.AppDate = row[8].ToString();
                    fur.OnlineDepositName = row[10].ToString();
                    fur.CompanyImg = row[19].ToString();
                    fur.CompanyName = row[26].ToString();
                    fur.StatusName = row[17].ToString();
                }
            }
            return fur;
        }
        public List<OnlineDepositApplyModels> getcontract()
        {
            List<OnlineDepositApplyModels> list = new List<OnlineDepositApplyModels>();
            OnlineDepositApplyModels fur;
            DataTable tb = dal.getcontract();
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new OnlineDepositApplyModels();
                    fur.OnlineDepositApplyID = int.Parse(row[0].ToString());
                    fur.OnlineDepositID = int.Parse(row[1].ToString());
                    fur.CustomerName = row[2].ToString();
                    fur.CustomerEmail = row[3].ToString();
                    fur.CustomerPhone = row[4].ToString();
                    fur.CustomerIncome = row[5].ToString();
                    fur.CustomerDOB = row[6].ToString();
                    fur.StatusID = int.Parse(row[7].ToString());
                    fur.AppDate = row[8].ToString();
                    fur.OnlineDepositName = row[10].ToString();
                    fur.CompanyImg = row[19].ToString();
                    fur.CompanyName = row[26].ToString();
                    fur.StatusName = row[17].ToString();
                    list.Add(fur);
                }
            }
            return list;
        }
        public List<OnlineDepositApplyModels> getcontractbystatus(int statusid)
        {
            List<OnlineDepositApplyModels> list = new List<OnlineDepositApplyModels>();
            OnlineDepositApplyModels fur;
            DataTable tb = dal.getcontractbystatus(statusid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new OnlineDepositApplyModels();
                    fur.OnlineDepositApplyID = int.Parse(row[0].ToString());
                    fur.OnlineDepositID = int.Parse(row[1].ToString());
                    fur.CustomerName = row[2].ToString();
                    fur.CustomerEmail = row[3].ToString();
                    fur.CustomerPhone = row[4].ToString();
                    fur.CustomerIncome = row[5].ToString();
                    fur.CustomerDOB = row[6].ToString();
                    fur.StatusID = int.Parse(row[7].ToString());
                    fur.AppDate = row[8].ToString();
                    fur.OnlineDepositName = row[10].ToString();
                    fur.CompanyImg = row[19].ToString();
                    fur.CompanyName = row[26].ToString();
                    fur.StatusName = row[17].ToString();
                    list.Add(fur);
                }
            }
            return list;
        }
        public List<TermDemandSavingCatModels> getTermDemandCate(int langid)
        {
            List<TermDemandSavingCatModels> list = new List<TermDemandSavingCatModels>();
            TermDemandSavingCatModels fur;
            DataTable tb = dal.getTermDemandCate(langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new TermDemandSavingCatModels();
                    fur.TermSavingsCateID = int.Parse(row[0].ToString());
                    fur.TermSavingsCateName = row[4].ToString();
                    list.Add(fur);
                }
            }
            return list;
        }
        public List<OnlineDepositModels> getTermDemandSavingDefault(int langid)
        {
            List<OnlineDepositModels> list = new List<OnlineDepositModels>();
            OnlineDepositModels fur;
            DataTable tb = dal.getTermDemandSavingDefault(langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new OnlineDepositModels();
                    fur.OnlineDepositID = int.Parse(row[0].ToString());
                    fur.OnlineDepositName = row[9].ToString();
                    fur.CompanyID = int.Parse(row[2].ToString());
                    fur.MinimumBalance = String.Format("{0:0,0}", double.Parse(row[3].ToString())).Replace(',', '.');
                    fur.MaximumBalance = String.Format("{0:0,0}", double.Parse(row[4].ToString())).Replace(',', '.');
                    fur.Description = WebUtility.HtmlDecode(row[10].ToString());
                    fur.Benefit = WebUtility.HtmlDecode(row[11].ToString());
                    fur.FeeContent = WebUtility.HtmlDecode(row[12].ToString());
                    fur.MoreInfo = WebUtility.HtmlDecode(row[13].ToString());
                    fur.TermSavingsCateID = int.Parse(row[5].ToString());
                    fur.Display = bool.Parse(row[6].ToString());
                    fur.CompanyName = row[22].ToString();
                    fur.CompanyImg = row[15].ToString();
                    fur.InterestVND = float.Parse(row[26].ToString());
                    fur.InterestEUR = float.Parse(row[27].ToString());
                    fur.InterestUSD = float.Parse(row[28].ToString());
                    list.Add(fur);
                }
            }
            return list;
        }
        public List<OnlineDepositModels> getTermDemandSavingDefaultByProvider(int CompanyID, int langid)
        {
            List<OnlineDepositModels> list = new List<OnlineDepositModels>();
            OnlineDepositModels fur;
            DataTable tb = dal.getTermDemandSavingDefaultByProvider(CompanyID, langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new OnlineDepositModels();
                    fur.OnlineDepositID = int.Parse(row[0].ToString());
                    fur.OnlineDepositName = row[9].ToString();
                    fur.CompanyID = int.Parse(row[2].ToString());
                    fur.MinimumBalance = String.Format("{0:0,0}", double.Parse(row[3].ToString())).Replace(',', '.');
                    fur.MaximumBalance = String.Format("{0:0,0}", double.Parse(row[4].ToString())).Replace(',', '.');
                    fur.Description = WebUtility.HtmlDecode(row[10].ToString());
                    fur.Benefit = WebUtility.HtmlDecode(row[11].ToString());
                    fur.FeeContent = WebUtility.HtmlDecode(row[12].ToString());
                    fur.MoreInfo = WebUtility.HtmlDecode(row[13].ToString());
                    fur.TermSavingsCateID = int.Parse(row[5].ToString());
                    fur.Display = bool.Parse(row[6].ToString());
                    fur.CompanyName = row[22].ToString();
                    fur.CompanyImg = row[15].ToString();
                    fur.InterestVND = float.Parse(row[26].ToString());
                    fur.InterestEUR = float.Parse(row[27].ToString());
                    fur.InterestUSD = float.Parse(row[28].ToString());
                    list.Add(fur);
                }
            }
            return list;
        }
        public List<OnlineDepositModels> getOnlineDeposit(int cate, string balance, int month, int langid)
        {
            List<OnlineDepositModels> list = new List<OnlineDepositModels>();
            OnlineDepositModels fur;
            DataTable tb = dal.getOnlineDeposit(cate, balance, month, langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new OnlineDepositModels();
                    fur.OnlineDepositID = int.Parse(row[0].ToString());
                    fur.OnlineDepositName = row[9].ToString();
                    fur.CompanyID = int.Parse(row[2].ToString());
                    fur.MinimumBalance = String.Format("{0:0,0}", double.Parse(row[3].ToString())).Replace(',', '.');
                    fur.MaximumBalance = String.Format("{0:0,0}", double.Parse(row[4].ToString())).Replace(',', '.');
                    fur.Description = WebUtility.HtmlDecode(row[10].ToString());
                    fur.Benefit = WebUtility.HtmlDecode(row[11].ToString());
                    fur.FeeContent = WebUtility.HtmlDecode(row[12].ToString());
                    fur.MoreInfo = WebUtility.HtmlDecode(row[13].ToString());
                    fur.TermSavingsCateID = int.Parse(row[5].ToString());
                    fur.Display = bool.Parse(row[6].ToString());
                    fur.CompanyName = row[22].ToString();
                    fur.CompanyImg = row[15].ToString();
                    fur.InterestVND = float.Parse(row[26].ToString());
                    fur.InterestEUR = float.Parse(row[27].ToString());
                    fur.InterestUSD = float.Parse(row[28].ToString());
                    list.Add(fur);
                }
            }
            return list;
        }
        public List<OnlineDepositModels> getTermDemandSavingListByProvider(int cate, string balance, int month, int CompanyID, int langid)
        {
            List<OnlineDepositModels> list = new List<OnlineDepositModels>();
            OnlineDepositModels fur;
            DataTable tb = dal.getTermDemandSavingListByProvider(cate, balance, month, CompanyID, langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new OnlineDepositModels();
                    fur.OnlineDepositID = int.Parse(row[0].ToString());
                    fur.OnlineDepositName = row[9].ToString();
                    fur.CompanyID = int.Parse(row[2].ToString());
                    fur.MinimumBalance = String.Format("{0:0,0}", double.Parse(row[3].ToString())).Replace(',', '.');
                    fur.MaximumBalance = String.Format("{0:0,0}", double.Parse(row[4].ToString())).Replace(',', '.');
                    fur.Description = WebUtility.HtmlDecode(row[10].ToString());
                    fur.Benefit = WebUtility.HtmlDecode(row[11].ToString());
                    fur.FeeContent = WebUtility.HtmlDecode(row[12].ToString());
                    fur.MoreInfo = WebUtility.HtmlDecode(row[13].ToString());
                    fur.TermSavingsCateID = int.Parse(row[5].ToString());
                    fur.Display = bool.Parse(row[6].ToString());
                    fur.CompanyName = row[22].ToString();
                    fur.CompanyImg = row[15].ToString();
                    fur.InterestVND = float.Parse(row[26].ToString());
                    fur.InterestEUR = float.Parse(row[27].ToString());
                    fur.InterestUSD = float.Parse(row[28].ToString());
                    list.Add(fur);
                }
            }
            return list;
        }
        public List<OnlineDepositModels> gettermdemandsavingrelati(int CompanyID, int OnlineDepositID,int langid)
        {
            List<OnlineDepositModels> list = new List<OnlineDepositModels>();
            OnlineDepositModels fur;
            DataTable tb = dal.gettermdemandsavingrelati(CompanyID, OnlineDepositID,langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new OnlineDepositModels();
                    fur.OnlineDepositID = int.Parse(row[0].ToString());
                    fur.OnlineDepositName = row[9].ToString();
                    fur.CompanyID = int.Parse(row[2].ToString());
                    fur.MinimumBalance = String.Format("{0:0,0}", double.Parse(row[3].ToString())).Replace(',', '.');
                    fur.MaximumBalance = String.Format("{0:0,0}", double.Parse(row[4].ToString())).Replace(',', '.');
                    fur.TermSavingsCateID = int.Parse(row[5].ToString());
                    fur.Description = WebUtility.HtmlDecode(row[10].ToString());
                    fur.Benefit = WebUtility.HtmlDecode(row[11].ToString());
                    fur.FeeContent = WebUtility.HtmlDecode(row[12].ToString());
                    fur.MoreInfo = WebUtility.HtmlDecode(row[13].ToString());
                    fur.Display = bool.Parse(row[6].ToString());
                    fur.CompanyName = row[22].ToString();
                    fur.CompanyImg = row[15].ToString();
                    list.Add(fur);
                }
            }
            return list;
        }
        public OnlineDepositModels getOnlineDepositByID(int OnlineDepositID, int langid)
        {
            OnlineDepositModels fur = new OnlineDepositModels();
            DataTable tb = dal.getOnlineDepositByID(OnlineDepositID, langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new OnlineDepositModels();
                    fur.OnlineDepositID = int.Parse(row[0].ToString());
                    fur.OnlineDepositName = row[9].ToString();
                    fur.CompanyID = int.Parse(row[2].ToString());
                    fur.MinimumBalance = String.Format("{0:0,0}", double.Parse(row[3].ToString())).Replace(',', '.');
                    fur.MaximumBalance = String.Format("{0:0,0}", double.Parse(row[4].ToString())).Replace(',', '.');
                    fur.Description = WebUtility.HtmlDecode(row[10].ToString());
                    fur.Benefit = WebUtility.HtmlDecode(row[11].ToString());
                    fur.FeeContent = WebUtility.HtmlDecode(row[12].ToString());
                    fur.MoreInfo = WebUtility.HtmlDecode(row[13].ToString());
                    fur.TermSavingsCateID = int.Parse(row[5].ToString());
                    fur.Display = bool.Parse(row[6].ToString());
                    fur.CompanyName = row[22].ToString();
                    fur.CompanyImg = row[15].ToString();
                }
            }
            return fur;
        }
        public OnlineDepositModels getOnlineDepositByIDManager(int OnlineDepositID, int langid)
        {
            OnlineDepositModels fur = new OnlineDepositModels();
            DataTable tb = dal.getOnlineDepositByIDManager(OnlineDepositID, langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new OnlineDepositModels();
                    fur.OnlineDepositID = int.Parse(row[0].ToString());
                    fur.OnlineDepositName = row[9].ToString();
                    fur.CompanyID = int.Parse(row[2].ToString());
                    fur.MinimumBalance = String.Format("{0:0,0}", double.Parse(row[3].ToString())).Replace(',', '.');
                    fur.MaximumBalance = String.Format("{0:0,0}", double.Parse(row[4].ToString())).Replace(',', '.');
                    fur.Description = WebUtility.HtmlDecode(row[10].ToString());
                    fur.Benefit = WebUtility.HtmlDecode(row[11].ToString());
                    fur.FeeContent = WebUtility.HtmlDecode(row[12].ToString());
                    fur.MoreInfo = WebUtility.HtmlDecode(row[13].ToString());
                    fur.TermSavingsCateID = int.Parse(row[5].ToString());
                    fur.Display = bool.Parse(row[6].ToString());
                    fur.CompanyName = row[22].ToString();
                    fur.CompanyImg = row[15].ToString();
                }
            }
            return fur;
        }
        public OnlineDepositModels getTOP1()
        {
            OnlineDepositModels fur = new OnlineDepositModels();
            DataTable tb = dal.getTOP1();
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new OnlineDepositModels();
                    fur.OnlineDepositID = int.Parse(row[0].ToString());
                }
            }
            return fur;
        }
        public List<OnlineDepositModels> getall(int langid)
        {
            List<OnlineDepositModels> list = new List<OnlineDepositModels>();
            OnlineDepositModels fur;
            DataTable tb = dal.getall(langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new OnlineDepositModels();
                    fur.OnlineDepositID = int.Parse(row[0].ToString());
                    fur.OnlineDepositName = row[9].ToString();
                    fur.CompanyID = int.Parse(row[2].ToString());
                    fur.MinimumBalance = row[3].ToString();
                    fur.MaximumBalance = row[4].ToString();
                    fur.Description = WebUtility.HtmlDecode(row[10].ToString());
                    fur.Benefit = WebUtility.HtmlDecode(row[11].ToString());
                    fur.FeeContent = WebUtility.HtmlDecode(row[12].ToString());
                    fur.MoreInfo = WebUtility.HtmlDecode(row[13].ToString());
                    fur.TermSavingsCateID = int.Parse(row[5].ToString());
                    fur.Display = bool.Parse(row[6].ToString());
                    fur.CompanyName = row[22].ToString();
                    fur.CompanyImg = row[15].ToString();
                    fur.FlagImage = row[27].ToString();
                    list.Add(fur);
                }
            }
            return list;
        }
        public int UpdateOnlineDeposit(OnlineDepositModels models, int langid)
        {
            if (dal.UpdateOnlineDeposit(models) > 0 && dal.UpdateOnlineDepositLang(models, langid) > 0)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
        public int InsertOnlineDeposit(OnlineDepositModels models)
        {
            if (dal.InsertOnlineDeposit(models) > 0)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
        public int InsertOnlineDepositLang(OnlineDepositModels models, int langid)
        {
            if (dal.InsertOnlineDepositLang(models, langid) > 0)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
        public int DeleteOnlineDeposit(int OnlineDepositID)
        {
            if (dal.DeleteOnlineDepositLang(OnlineDepositID) > 0 && dal.DeleteOnlineDeposit(OnlineDepositID) > 0)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }


    }
}
